/// Author: QP
/// Version: 1.0
/// Date:2022/07
/// 互联互通文档FHIR服务器设置类
/// notice: this class works on FHIR repository only!
Class HCC.Utils.FHIRServer Extends %RegisteredObject
{

/// Reset fhir repository
ClassMethod ResetRepository(pServiceName = "/csp/healthshare/fhirns/fhir/r4")
{
	set repoInstance = ##class(HS.FHIRServer.RepoInstance).FindByUrl(pServiceName)
	set repoManager = ##class(HS.FHIRServer.Storage.Json.RepoManager).getInstance(repoInstance.repo)
	set options("deleteDataOnly") = 1
	do repoManager.DeleteService(repoInstance.serviceId, .options)
}

/// Jira IF-1592, to avoid FHIR spec bug on unicode whitespace!
ClassMethod Correction()
{
	If $D(^HS.FHIRServer.Meta($lb("hl7.fhir.r4.core@4.0.1"))) 
	{
    Set ^HS.FHIRServer.Meta($lb("hl7.fhir.r4.core@4.0.1"),"pti","string","rx") = "[\r\n\t\u0020-\uFFFF]*"
    Set ^HS.FHIRServer.Meta($lb("hl7.fhir.r4.core@4.0.1"),"pti","markdown","rx") = "[\r\n\t\u0020-\uFFFF]*"
  	}
}

/// initialize code tables to make sure FHIR generated correctly from SDA
ClassMethod CodeTableInit()
{
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","2")	=	"female"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","女性")	=	"female"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","1")	=	"male"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","男性")	=	"male"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","未知的性别")	=	"unknown"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","0")	=	"unknown"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","未说明的性别")	=	"unknown"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.Gender","administrative-gender|4.0.1","9")	=	"unknown"
	      
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","10")	=	"U"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","未婚")	=	"U"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","20")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","已婚")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","21")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","初婚")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","22")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","再婚")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","23")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","复婚")	=	"M"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","30")	=	"W"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","丧偶")	=	"W"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","40")	=	"D"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","离婚")	=	"D"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","90")	=	"UNK"
	Set ^HS.XF.LookupTable("SDA3","vR4","HS.SDA3.CodeTableDetail.MaritalStatus","marital-status","未说明的婚姻状况")	=	"UNK"
}

}
